<!--
* description: 门店管理-新增、修改弹窗
* author: dinggf
* createdDate: 2019-10-22
-->
<template>
  <section class="editStore">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      width="1000px"
      @close="sendCode"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :style-type="$store.state.app.dialogType"
      />
      <div class="filter-container filter-params">
        <el-row
          v-loading="dlrLOading"
          :gutter="26"
          element-loading-text="正在保存,请稍等..."
        >
          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :key="comp.compKey"
            :custom-obj="comp.customObj"
            :o-fields="comp.oFields"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :code="formField[comp.codeField]"
            :step="comp.step"
            :text="formField[comp.textField]"
            :data-to-object="comp.dataToObject"
            :disabled="comp.disabled"
            :is-require="comp.isRequire"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :date-type="comp.dateType"
            :format="comp.dateFormat"
            :parent-fileds="comp.parentFileds"
            :input-type="comp.inputType"
            :must-fields="comp.mustFields || ''"
            :date-options-type="comp.dateOptionsType"
            :is-mul="false"
            :clearable="comp.clearable"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
          />
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          v-show="comp.show"
          :key="comp.compKey"
          :type="comp.type"
          :icon="comp.icon"
          @click="comp.clickEvent"
        >{{ comp.text }}</el-button>
      </div>
    </el-dialog>
  </section>
</template>

<script>
import { formMixins } from '@/components/mixins/formMixins'
import { orgApis } from '@/api/apiList/org'
export default {
  components: {
    dialogHeader: () => import('@/components/dialogHeader') // 弹窗标题
  },
  mixins: [formMixins],
  data() {
    // 弹窗页面标识（由引用页面赋值）
    const viewPageCode = 'veDlrInfoManagesEdit'
    return {
      // loading
      dlrLOading: false,
      // 保存API配置对象
      apiConfig: orgApis.mdmOrgDlrMutationSave,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey2',
          type: 'primary',
          size: 'small',
          clickEvent: () => this.mySave(),
          icon: 'iconfont  icon-preservation',
          text: this.$t('sys.button.confirm'),
          show: true
        },
        {
          compKey: 'btnKey1',
          type: '',
          size: 'small',
          clickEvent: () => this.reset(),
          icon: 'iconfont  icon-reset',
          text: this.$t('sys.button.reset'),
          show: true
        }
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          : [],
      // 静态组件-查询条件
      staticTableComponents: [
        {
          compKey: 'compKey1',
          labelName: '门店大类：',
          lookuptype: 'DB0062',
          codeField: 'orgType',
          // disabled: true,
          isRequire: true,
          parentFileds: 'lookupValueCode',
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey2',
          labelName: '门店类型：',
          lookuptype: 'DB0049',
          codeField: 'dlrType',
          // disabled: true,
          isRequire: true,
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          clearable: false,
          isMust: true
        },

        {
          compKey: 'compKey8',
          labelName: '门店编码：', /* 门店代码*/
          codeField: 'dlrCode',
          isRequire: true,
          parentFileds: 'disabled:updateControlId-dlrCode',
          disabled: null,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey12',
          labelName: '门店级别：',
          lookuptype: 'VE9001',
          // disabled: true,
          codeField: 'dlrLevel',
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey121',
          labelName: '大区：',
          isRequire: true,
          codeField: 'bigAreaId',
          textField: 'bigAreaName',
          customObj: { api: orgApis.mdmOrgBigAreaList },
          component: () => import('@/components/org/commonSelect'),
          oFields: 'bigAreaId,bigAreaName',
          type: 'dropdownList',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey122',
          labelName: '小区：',
          codeField: 'smallAreaId',
          disabled: true,
          textField: 'smallAreaName',
          component: () => import('@/components/org/commonSelect'),
          type: 'dropdownList',
          parentFileds: 'value:bigAreaId,disabled:bigAreaId-smallAreaId--false',
          oFields: 'smallAreaId,smallAreaName',
          customObj: {
            listQuery: { bigAreaId: '' },
            api: orgApis.mdmOrgSmallAreaList
          },
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey10',
          labelName: '门店名称：',
          codeField: 'dlrShortName',
          // disabled: true,
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey11',
          labelName: '门店全称：',
          codeField: 'dlrFullName',
          // disabled: true,
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          clearable: false,
          isMust: true
        },

        {
          compKey: 'compKey13',
          labelName: '门店英文名：',
          codeField: 'dlrEnName',
          // disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          clearable: false,
          isMust: true
        },

        {
          compKey: 'compKey14',
          labelName: '曾用名：',
          codeField: 'dlrNameOld',
          // disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey9',
          labelName: '建店状态：',
          lookuptype: 'DB0066',
          codeField: 'dlrStatus',
          isRequire: true,
          dataToObject: {
            placeholder: '请选择'
          },
          // disabled: true,
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey24',
          labelName: '注册资金：',
          codeField: 'registerMoney',
          // disabled: true,
          component: () => import('@/components/org/commonInput/numberInput'),
          step: 1,
          isRequire: true,
          type: 'inputText',
          validrule: {
            isformat: /^[+]{0,1}(\d+)$/,
            min: 0,
            max: 100000000
          },
          dataToObject: {
            min: 0,
            max: 100000000
          },
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey25',
          labelName: '统一社会信用代码：',
          codeField: 'guno',
          // disabled: true,/[^a-zA-Z0-9]/g
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          validrule: {
            min: 1,
            isformat: /^[A-Za-z0-9]{0,40}$/
          },
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey251',
          labelName: '所属组织：',
          codeField: 'orgId',
          component: () => import('../globalManagement/orgNameInput'),
          otherField: 'orgTreeId-orgId',
          disabled: true,
          parentFileds: 'disabled:isEdit-orgId-true',
          textField: 'orgName',
          isRequire: true,
          dataToObject: { orgBelongType: true },
          type: 'propus',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey26',
          labelName: '邮箱：',
          codeField: 'email',
          // disabled: true,
          validrule: { noRequire: false, isEmail: true, min: 8 },
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey261',
          labelName: '邮编：',
          codeField: 'zip',
          validrule: { minlength: 6 },
          dataToObject: { maxLength: 6 },
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey16',
          labelName: '管理员账号：',
          codeField: 'dlrCode',
          disabled: true,
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          parentFileds: 'disabled:updateControlId-userName',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey17',
          labelName: '管理员密码：',
          codeField: 'password',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          inputType: 'password',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey18',
          labelName: '管理员角色：' /* 管理员角色*/,
          codeField: 'roleName',
          textField: 'roleId',
          isRequire: true,
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          clearable: false,
          isMust: true
        },

        {
          compKey: 'compKey3',
          labelName: '上线状态：',
          codeField: 'onlineFlag',
          // disabled: true,
          lookuptype: 'VE0629',
          isRequire: true,
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey22',
          labelName: '上线日期：',
          codeField: 'dlrBussDate',
          // disabled: true,
          isRequire: true,
          dateType: 'date',
          // dateFormat: 'yyyy-MM-dd HH:mm:ss',
          dateFormat: 'yyyy-MM-dd',
          component: () => import('@/components/org/datePicker/datePicker'),
          type: 'datePicker',
          clearable: false,
          isMust: true
          // parentFileds: "disabled:dlrBussDate-dlrBussDate",

        },
        {
          compKey: 'compKey4',
          labelName: '省份：',
          codeField: 'provinceId',
          // disabled: true,
          isRequire: true,
          component: () => import('@/components/org/ProvinceQuery'),
          type: 'dropdownList',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey5',
          labelName: '城市：',
          codeField: 'cityId',
          // disabled: true,
          parentFileds: 'provinceId',
          isRequire: true,
          component: () => import('@/components/org/CitySelect'),
          type: 'dropdownList',
          clearable: false,
          isMust: true
        },

        {
          compKey: 'compKey7',
          labelName: '区县：',
          codeField: 'countyId',
          // disabled: true,
          parentFileds: 'cityId',
          component: () => import('@/components/org/CountySelect'),
          type: 'dropdownList',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey27',
          labelName: '建店地址：',
          codeField: 'linkAddr',
          // disabled: true,
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey20',
          labelName: '气候状态：',
          lookuptype: 'VE0180',
          codeField: 'climateStatus',
          // disabled: true,
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey35',
          labelName: '救援热线：',
          codeField: 'rescuHotline',
          // validrule: { noRequire: true, isTel: true },
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey31',
          labelName: '紧急救援电话：',
          codeField: 'urgSosTel',
          // disabled: true,
          isRequire: true,
          validrule: { noRequire: true, isPhone: true },
          dataToObject: { maxLength: 15 },
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey32',
          labelName: '联系电话：',
          codeField: 'phone',
          // disabled: true,
          isRequire: true,
          validrule: { isFixedTel: true },
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey28',
          labelName: '门店业务类型：', // 新加字段
          codeField: 'dlrBusiStatus',
          isRequire: true,
          lookuptype: 'DB0080',
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey30',
          labelName: 'POSID：', // 新加字段
          codeField: 'posid',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          clearable: false,
          isMust: true
        },

        {
          compKey: 'compKey40',
          labelName: 'SAP门店编码：', // 新加字段
          codeField: 'sapDlrId',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          disabled: true,
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey401',
          labelName: '工厂：', // 新加字段
          codeField: 'factory',
          component: () => import('@/components/org/commonInput'),
          dataToObject: { maxLength: 50 },
          type: 'inputText',
          clearable: false,
          isMust: true
        },

        {
          compKey: 'compKey41',
          labelName: '营业开始时间：', // 新加字段
          codeField: 'dlrBussStartDate',
          component: () => import('@/components/org/datePicker/datePicker'),
          dateType: 'datetime',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey42',
          labelName: '营业截止时间：', // 新加字段
          codeField: 'dlrBussEndDate',
          component: () => import('@/components/org/datePicker/datePicker'),
          dateType: 'datetime',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          clearable: false,
          isMust: true,
          disabled: true
        },
        {
          compKey: 'compKey43',
          labelName: '开户银行名称：', // 新加字段
          codeField: 'invBank',
          component: () => import('@/components/org/commonInput'),
          isInput: true,
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey44',
          labelName: '银行代码：', // 新加字段
          codeField: 'invBankCode',
          component: () => import('@/components/org/commonInput'),
          isInput: true,
          clearable: false,
          isMust: true,
          isRequire: true
        },
        {
          compKey: 'compKey49',
          labelName: '开户银行帐号：', // 新加字段
          codeField: 'invAccount',
          component: () => import('@/components/org/commonInput'),
          isInput: true,
          clearable: false,
          isMust: true,
          isRequire: true
        },
        {
          compKey: 'compKey45',
          labelName: '开票名称：', // 新加字段
          codeField: 'invName',
          component: () => import('@/components/org/commonInput'),
          isInput: true,
          isRequire: true,
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey46',
          labelName: '开票地址：', // 新加字段
          codeField: 'invAddr',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          isInput: true,
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey47',
          labelName: '开票电话：', // 新加字段
          codeField: 'invoicePhone',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          isInput: true,
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey50',
          labelName: '是否启用透明化车间：',
          lookuptype: 'DB0064',
          codeField: 'isTransparent ',
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey51',
          labelName: '上级直营店编码',
          codeField: 'directDlrCode',
          disabled: true,
          component: () => import('@/components/ve/multipleSearchInput'),
          parentFileds: 'disabled:dlrType-directDlrCode--false',
          type: 'inputText',
          dataToObject: {
            // 控制弹窗页面 搜索 网格 元素
            tableComponents: [
              {
                compKey: 'compKey1',
                labelName: '门店编码：',
                codeField: 'dlrCode',
                component: () => import('@/components/org/commonInput'),
                type: 'inputText',
                isMul: false,
                clearable: false,
                isMust: true
              },
              {
                compKey: 'compKey2',
                labelName: '门店名称：',
                codeField: 'dlrShortName',
                component: () => import('@/components/org/commonInput'),
                type: 'inputText',
                isMul: false,
                clearable: false,
                isMust: true
              }
            ],
            tableCols: [
              {
                prop: 'updateControlId',
                label: '并发控制ID',
                hidden: true,
                alwaysHidden: true
              },
              {
                prop: 'dlrId',
                label: '门店Id',
                hidden: true,
                alwaysHidden: true
              },
              {
                prop: 'dlrCode',
                label: '门店编码'
              },
              {
                prop: 'dlrShortName',
                label: '门店简称'
              },
              {
                prop: 'dlrFullName',
                label: '门店全称'
              }
            ],
            formField: {
              dlrType: '',
              orgType: '',
              dlrCode: '',
              dlrShortName: ''
            },
            returnField: {
              prop: 'dlrCode',
              label: '门店编码'
            },
            api: orgApis.mdmOrgdlrQueryByPage
          },
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey55',
          labelName: '经度：',
          codeField: 'lng',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          validrule: {
            noRequire: true,
            resectMessage: {
              isformat: '经度在-180~180保留最多六位小数'
            },
            isformat: /^[\-\+]?(0?\d{1,2}(\.\d{0,6})?|1[0-7]?\d{1}(\.\d{0,6})?|180(\.0{0,6})?)$/
          },
          isInput: true,
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey56',
          labelName: '纬度：',
          codeField: 'lat',
          isRequire: true,
          validrule: {
            noRequire: true,
            resectMessage: {
              isformat: '纬度在-90~90保留最多六位小数'
            },
            isformat: /^[\-\+]?([0-8]?\d{1}(\.\d{1,6})?|90(\.0{1,6})?)$/
          },
          component: () => import('@/components/org/commonInput'),
          isInput: true,
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey48',
          labelName: '启用状态：', // 启用中台
          codeField: 'isEnable',
          isRequire: true,
          component: () => import('@/components/org/isEnable/isEnableOne'),
          type: 'dropdownList',
          clearable: false,
          isMust: true
        },
        {
          compKey: 'compKey29',
          labelName: '并发控制id',
          codeField: 'updateControlId',
          // disabled: true,
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: false
        }
      ],
      textMap: {
        edit: '门店详情查看',
        add: '门店增加'
      },
      formField: this.$utils.getFormField(this, {
        lng: '',
        lat: '',
        isTransparent: '',
        directDlrCode: '',
        bigAreaId: '',
        smallAreaId: '',
        roleName: '',
        roleOrgType: 1,
        orgType: '',
        dlrSort: '',
        onlineFlag: '',
        provinceId: '',
        cityId: '',
        countyId: '',
        dlrCode: '',
        dlrShortName: '',
        dlrFullName: '',
        dlrLevel: '',
        dlrEnName: '',
        dlrNameOld: '',
        // stockRight: '',
        userName: '',
        password: '',
        // roleId: '',
        roleId: '',
        climateStatus: '',
        isEnable: '1',
        registerMoney: 0,
        guno: '',
        orgId: '',
        orgName: '',
        email: '',
        zip: '',
        linkAddr: '',
        carBrandCn: '',
        updateControlId: '',
        updId: '',
        dlrId: '',
        dlrType: '',
        dlrStatus: '',
        urgSosTel: '',
        phone: '',
        // parentDlrId: '',
        rescuHotline: '',
        parentDlrName: '',
        lookupValueCode: '1',
        userId: '',
        dlrBusiStatus: '',
        isEdit: '',
        dlrBussDate: '',
        posid: '',
        sapDlrId: '',
        factory: '',
        dlrBussStartDate: '',
        dlrBussEndDate: '',
        invBank: '',
        invBankCode: '',
        invAccount: '',
        invName: '',
        invAddr: '',
        invoicePhone: ''
        // dlrTypeName: ''
        // cityName: '',
        // orgTypeName: '',
        // dlrStatusName: ''
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode], null, 'formComponents'),

      isChangeEnable: '',
      isChangeRoleId: '',
      roleOptions: []
    }
  },
  watch: {
    'curPopupsVisible'(newVal) {
      if (newVal) {
        if (this.popupsState === 'add') {
          this.formField.orgType = ''
        }
        const that = this
        const queryObj = {
        // api配置
          apiConfig: orgApis.sysRoleDlrMgrQuery,
          // 条件/实体参数（变量），根据typeParam中的定义配置
          variables: {
            enabled: '1'
          }
        }
        // 转换了中台请求格式数据
        var paramD = that.$getParams(queryObj)
        // 调用中台API方法（可复用）
        that.$requestAPI(paramD).then(response => {
          if (response.result === '1') {
            this.roleOptions = response.rows
            if (this.formField.orgType) {
              this.switchRole(this.formField.orgType)
            }
          }
        })
      }
    },
    'formField.orgType': {
      handler: function(newVal, oldVal) {
        if (newVal) {
          this.switchRole(newVal)
        }
        // this.switchks(newVal)
      },
      immediate: false
    },
    'formField.dlrType'(newVal, oldVal) {
      if (newVal) {
        this.switchDlrCode(newVal)
      }
    },
    'formField.roleId'(newVal, oldVal) {
      if (this.curPopupsVisible === true) {
        if (oldVal !== newVal) {
          this.isChangeRoleId = '1'
        } else {
          (
            this.isChangeRoleId = ''
          )
        }
      }
    },
    'formField.isEnable'(newVal, oldVal) {
      if (this.curPopupsVisible === true) {
        if (oldVal !== newVal) {
          this.isChangeEnable = '1'
        } else {
          (
            this.isChangeEnable = ''
          )
        }
      }
    },
    'formField.dlrBussStartDate'(newVal, oldVal) {
      this.tableComponents.find(o => o.codeField === 'dlrBussEndDate').disabled = !newVal
    },
    'formField.dlrBussEndDate'(newVal, oldVal) {
      if (newVal) {
        if (new Date(this.formField.dlrBussStartDate).getTime() >= new Date(newVal).getTime()) {
          this.$message('营业截止时间不能小于开始时间!')
          this.$nextTick(() => {
            this.formField.dlrBussEndDate = ''
            this.$refs['compKey42'][0].$children[0].$children[1].focus()
          })
        }
      }
    }
  },
  methods: {
    // 上级直营店编码和门店类型联动
    switchDlrCode(val) {
      this.staticTableComponents.forEach(item => {
        if (item.codeField === 'directDlrCode') {
          if (val === '2') {
            item.dataToObject.formField.dlrType = '1'
            item.dataToObject.formField.orgType = ''
          } else {
            item.dataToObject.formField.dlrType = ''
            item.dataToObject.formField.orgType = '1,3,4'
          }
        }
      })
    },
    switchRole(val) {
      switch (val) {
        case '1':
          this.formField.roleId = this.findId('DLRT01').roleId
          this.formField.roleName = this.findId('DLRT01').roleName
          break
        case '2':
          this.formField.roleId = this.findId('DLRT02').roleId
          this.formField.roleName = this.findId('DLRT02').roleName
          break
        case '3':
          this.formField.roleId = this.findId('DLRT03').roleId
          this.formField.roleName = this.findId('DLRT03').roleName
          break
        case '4':
          this.formField.roleId = this.findId('DLRT04').roleId
          this.formField.roleName = this.findId('DLRT04').roleName
          break
        default:
          this.formField.roleId = this.findId('JS01').roleId
          this.formField.roleName = this.findId('JS01').roleName
      }
    },
    // 门店大类为快闪店时，设置门店类型为直营店禁用
    // 0125版本取消限制
    switchks(val) {
      this.staticTableComponents.forEach(item => {
        if (item.codeField === 'dlrType') {
          if (val === '5') {
            item.disabled = true
            this.formField.dlrType = '1'
          } else {
            item.disabled = false
            this.formField.dlrType = this.dynamicEditRowData.dlrType
          }
        }
      })
    },
    findId(val) {
      var a = this.roleOptions.find(item => item.roleCode === val)
      return a
    },
    // 初始化密码
    onCreated() {
      if (this.popupsState === 'edit') {
        this.formField.password = '***'
        this.formField.isEdit = true
      } else {
        this.formField.isEdit = ''
      }
    },
    // 去空格
    Trim(str, is_global) {
      var result
      result = str.replace(/(^\s+)|(\s+$)/g, '')
      if (is_global.toLowerCase() === 'g') {
        result = result.replace(/\s/g, '')
      }
      return result
    },
    mySave() {
      console.log(this.formField.dlrBussDate)
      delete this.formField.roleOrgType
      delete this.formField.parentDlrName
      // 门店管理员账号=门店编码
      this.formField.userName = this.formField.dlrCode
      this.$utils.validataMoth(this, 'validpopup')

      const saveObj = {}
      this.$utils.deepClone(saveObj, this.formField)

      saveObj.lookupValueCode = undefined
      if (this.valid) {
        this.dlrLOading = true
        if (this.popupsState === 'edit' && saveObj.password === '***') {
          // saveObj.userName = undefined
          saveObj.password = undefined
        } else {
          // 对密码进行加密
          const Base64 = require('js-base64').Base64
          saveObj.password = Base64.encode(saveObj.password)
        }
        // 是否修改角色和状态

        if (this.isChangeEnable === '' && this.isChangeRoleId === '' && saveObj.password !== '***') {
          saveObj.userId = undefined
        }
        for (var i in saveObj) {
          if (i !== 'dlrBussDate' && i !== 'dlrBussStartDate' && i !== 'dlrBussEndDate' && saveObj[i] && typeof (saveObj[i]) === 'string') {
            saveObj[i] = this.Trim(saveObj[i], 'g')
          }
        }
        this.saveForm(saveObj, () => { this.dlrLOading = false })
        if (this.popupsState !== 'edit') {
          this.$emit('queryTree')
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
/deep/ .filter-params .el-row {
  margin-right: 20px !important;
}
</style>
